#include "TElidedLabel.h"
#include <QFontMetrics>

TElidedLabel::TElidedLabel(const QString& text, QWidget *parent)
  : QLabel(text, parent), _content(text)
{
}

void TElidedLabel::setContent(const QString& newText)
{
  _content = newText;
  setToolTip(newText);
  setText(elidedText());
}

void TElidedLabel::resizeEvent(QResizeEvent* event)
{
  QLabel::resizeEvent(event);
  setText(elidedText());
}

QString TElidedLabel::elidedText() const
{
  QFontMetrics fm = fontMetrics();
  return fm.elidedText(_content, Qt::ElideRight, contentsRect().width(), Qt::TextSingleLine);
}
